/*
 * Copyright (c) 2013, SRI International
 * All rights reserved.
 * Licensed under the The BSD 3-Clause License;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 * 
 * http://opensource.org/licenses/BSD-3-Clause
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * Neither the name of the aic-web-praise nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.sri.ai.lpitools.cobra.server.data.api;

import org.apache.xmlrpc.XmlRpcException;

import com.sri.ai.lpitools.cobra.gwtutil.dataobjects.shared.LWPException;


/**
 * Interface that the RCPCOBRAServerImpl uses to access data, be it from files, a mock for testing,
 * or any future desired method.
 * @author dabraham
 *
 */
public interface DataInterface {

	/**
	 * Returns a JSON string representation of a list of ModelInfo Objects
	 * @param user, UserName of the current User
	 * @return, Returns a JSON string representation of a list of ModelInfo Objects 
	 * 			or "Not Valid" if the user has no models to list
	 * @throws XmlRpcException 
	 */
	public String getModelList(String user) throws LWPException;

	/**
	 * Returns a JSON string representation of a ModelInfo Object
	 * @param user, UserName of the current User
	 * @param modelName, Name of the model to be opened
	 * @return, Returns a JSON string representation of a ModelInfo Object
	 * 			or ""Not Valid" otherwise
	 * @throws XmlRpcException 
	 */
	public String openModel(String user, String modelTitle) throws LWPException;
	
	/**
	 * This function replaces the whole model that is currently saved
	 * Returns true if model was saved and false otherwise
	 * @param user, UserName of the current User
	 * @param title, The title of the model to save
	 * @param model, A JSON representation of a ModelInfo object
	 * @return, Returns true if model was saved and false otherwise
	 * @throws XmlRpcException 
	 */
	public boolean saveModel(String user, String title, String model) throws LWPException;

	/**
	 * This function replaces the model info of the currently saved model
	 * Returns true if model was saved and false otherwise
	 * @param user, UserName of the current User
	 * @param title, The title of the model to save
	 * @param model, A JSON representation of a ModelInfo object
	 * @return, Returns true if model was saved and false otherwise
	 * @throws XmlRpcException 
	 */
	public boolean saveModelInfo(String user, String title, String model) throws LWPException;
	
	/**
	 * This function replaces the model body of the currently saved model
	 * Returns true if model was saved and false otherwise
	 * @param user, UserName of the current User
	 * @param title, The title of the model to save
	 * @param model, A JSON representation of a ModelInfo object
	 * @return, Returns true if model was saved and false otherwise
	 * @throws XmlRpcException 
	 */
	public boolean saveModelBody(String user, String title, String model) throws LWPException;
	
	/**
	 * This function deletes a currently saved model
	 * @param user, UserName of the current User
	 * @param modelTitle, Title of the model to delete
	 * @return, Returns True if model was deleted  or if it does not exist and false otherwise
	 * @throws XmlRpcException 
	 */
	public boolean deleteModel(String user, String modelTitle) throws LWPException;
	
	/**
	 * This function returns true if the query was saved correctly
	 * @param user, UserName of the current User
	 * @param title, Title of query to save
	 * @param query, JSON representation of a QueryInfo object
	 * @return, Returns true if the query was saved and false otherwise
	 * @throws XmlRpcException 
	 */
	public boolean saveQuery(String user, String title, String query) throws LWPException;	
	
	/**
	 * This function returns a JSON string representation of a list of QueryInfo Objects
	 * @param user, UserName of the current User
	 * @return, This function returns a JSON string representation of a list of QueryInfo Objects
	 *			or "Not Valid" otherwise
	 * @throws XmlRpcException 
	 */
	public String listQueries(String user) throws LWPException;
	
	/**
	 * Returns a JSON representation of a QueryInfo object
	 * @param user, UserName of the current User
	 * @param queryTitle, Title of query to open
	 * @return, Returns a JSON representation of a QueryInfo object
	 *			or "Not Valid" otherwise
	 * @throws XmlRpcException 
	 */
	public String getQuery(String user, String queryTitle) throws LWPException;
	
	/**
	 * Returns true if the given query was deleted and false otherwise
	 * @param user, UserName of the current User
	 * @param queryTitle, Title of query to  delete
	 * @return, Returns true if the given query was deleted or if it does not exist and false otherwise
	 * @throws XmlRpcException 
	 */
	public boolean deleteQuery(String user, String queryTitle) throws LWPException;
	
	/**
	 * This function returns a JSON string representation of a list of EvidenceInfo Objects
	 * @param user, UserName of the current User
	 * @return, Returns a JSON string representation of a list of EvidenceInfo Objects
	 *			or "Not Valid" otherwise 	
	 * @throws XmlRpcException 
	 */
	public String listEvidences(String user) throws LWPException;
	
	/**
	 * Returns a JSON representation of a EvidenceInfo object
	 * @param user, UserName of the current User
	 * @param evidenceTitle, Title of Evidence to open
	 * @return, Returns a JSON representation of a EvidenceInfo object
	 *			or "Not Valid" otherwise
	 * @throws XmlRpcException 
	 */
	public String getEvidence(String user, String evidenceTitle) throws LWPException;
	
	/**
	 * Returns a JSON representation of a EvidenceInfo object
	 * @param user, UserName of the current User
	 * @param title, Title of Evidence to open
	 * @param evidence, JSON representation of a EvidenceInfo object
	 * @return, Returns true if the evidence was saved and false otherwise
	 * @throws XmlRpcException 
	 */
	public boolean saveEvidence(String user, String title, String evidence) throws LWPException;
	
	/**
	 * Returns true if the given evidence was deleted and false otherwise
	 * @param user, UserName of the current User
	 * @param evidenceTitle, Title of evidence to delete
	 * @return, Returns true if the given evidence was deleted or if it does not exist and false otherwise
	 * @throws XmlRpcException 
	 */
	public boolean deleteEvidence(String user, String evidenceTitle) throws LWPException;

	/**
	 * Returns a JSON representation of a UserInfo object for the given username
	 * @param user, UserName of the user to check
	 * @return, Returns a JSON representation of a UserInfo object for the given username
	 * 			or "Not Valid" otherwise
	 * @throws XmlRpcException 
	 */
	public String checkUser(String user) throws LWPException;
	
	/**
	 * Returns true if the given user was saved
	 * @param user, JSON representation of a UserInfo object
	 * @return, Returns true if the given user was saved
	 * @throws XmlRpcException 
	 */
	public boolean saveUser(String user) throws LWPException;
	
	/**
	 * Return true if the given user was deleted
	 * @param user, UserName of the user to be deleted
	 * @return, Returns true if the given user was deleted or if it does not exist and false otherwise
	 * @throws XmlRpcException 
	 */
	public boolean deleteUser(String user) throws LWPException;
	
	/**
	 * Returns a JSON representation of a list of UserInfo objects for the system
	 * @return, Returns a JSON representation of a list of UserInfo objects
	 * @throws XmlRpcException 
	 */
	public String getUsers() throws LWPException;
	
	public void close() throws LWPException;

}
